home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / desktop_eoe.idb / usr / lib / desktop / rcpDevice.z / rcpDevice
Encoding:
Text File  |  1997-02-07  |  4.2 KB  |  192 lines

  1. #!/bin/sh
  2. #transferDevRcp
  3.  
  4. # NOTE: This is a sample transfer device for illustration purposes.
  5. # It does not currently have adequate error handling.
  6.  
  7. # Preferance variables that control functionality.
  8. login=$USER    # Can set to be guest
  9.  
  10. hostName=`expr \`basename $0\` : '.*\.\(.*\)'`
  11.  
  12. if [ -z "$hostName" -a $1 != Action ]; then
  13.     hostName="a remote machine"
  14. fi
  15.  
  16. case $1
  17.     in
  18.     "menu")
  19.         echo "import Get files from $hostName"
  20.         echo "export Send files to $hostName"
  21.     ;;
  22.     "versionsOK")
  23.         echo "remote local"
  24.     ;;
  25.     "query")
  26.         #   Ask whether to copy files in or out
  27.         wsh -C 6,32,3,32 -t "RCP files"\
  28.         -n "transfer" -p 400,400 -s 65,14 -m 120,40 -H -r1000 \
  29.         -c $0 Action query
  30.         ;;
  31.     "import")
  32.         #    If a directory is selected, then cd there first.
  33.         if [ "$SELECTED" ]; then
  34.         set -- $SELECTED
  35.         if [ $# -gt 1 ]; then
  36.             inform "There are too many selections."
  37.             exit 1
  38.         fi
  39.         # We only allow to copy to a directory, not a specific file.
  40.         if [ -d $SELECTED ]; then
  41.             cd $SELECTED
  42.         else
  43.             inform "Selected item is not a directory."
  44.             exit 1
  45.         fi
  46.         fi
  47.         wsh -C 6,32,3,32 -t "RCP files from $hostName"\
  48.         -n "transfer" -p 400,400 -s 65,14 -m 120,40 -H -r1000 \
  49.         -c $0 Action import
  50.     ;;
  51.     "export")
  52.         wsh -C 6,32,3,32 -t "RCP files to $hostName" \
  53.         -n "transfer" -p 400,400 -s 65,14 -m 120,40 -H -r1000 \
  54.         -c $0 Action export $2
  55.     ;;
  56.  
  57.     "Action")
  58.         case $2
  59.         in
  60.             "query")
  61.             while true; do
  62.                 tput bold
  63.                 echo "Copy in (i) or out (o)? \c"
  64.                 tput rmul
  65.                 read choice
  66.                 case $choice in
  67.                     i|I) exec $0 Action import ;;
  68.                     o|O) exec $0 Action export ;;
  69.                 esac
  70.             done
  71.             ;;
  72.             "import")
  73.             if [ -z "$hostName" ]; then
  74.                 tput bold
  75.                 echo "Enter the name of a remote machine:"
  76.                 tput rmul
  77.                 read hostName
  78.             fi
  79.             tput bold
  80.             echo "Enter the name of a file or directory on $hostName to copy:"
  81.             tput rmul
  82.             read fileName
  83.  
  84.             # set up the path as rcp would for $login
  85.             case $fileName
  86.                 in
  87.                 ~* | /*)
  88.                     # leave as is.
  89.                     ;;
  90.                 *)
  91.                     fileName="~$login/$fileName"
  92.                     ;;
  93.             esac
  94.  
  95.             echo
  96.             echo "Attempting an rcp as $login."
  97.  
  98.             # Try as guest if no permission for user.
  99.             # Permission check for machine, not file.
  100.             errStr=`rsh "$hostName" -l "$login" echo 2>&1`
  101.             success=$?
  102.             echo "$errStr"
  103.             if [ $success -ne 0 ]; then
  104.                 if [ "$errStr" = "Permission denied." -o \
  105.                     "$errStr" = "Login incorrect." ]; then
  106.                 login=guest
  107.                 echo
  108.                 echo "Attempting an rcp as guest."
  109.                 success=0;
  110.                 fi
  111.             fi
  112.  
  113.             # RCP for real (if it makes sense).
  114.             if [ $success -eq 0 ]; then
  115.                 rcp -rv "$login@$hostName:$fileName" .
  116.                 success=$?
  117.             fi
  118.             ;;
  119.             "export")
  120.             if [ -z "$hostName" ]; then
  121.                 tput bold
  122.                 echo "Enter the name of a remote machine:"
  123.                 tput rmul
  124.                 read hostName
  125.             fi
  126.  
  127.             # SELECTED wasn't getting set properly, so set it explicitly
  128.             SELECTED="$3"
  129.             while [ -z "$SELECTED" ]; do
  130.                 tput bold
  131.                 echo "Enter the name of a local file or directory to write:"
  132.                 tput rmul
  133.                 read SELECTED
  134.             done
  135.             tput bold
  136.             echo "Enter the name of a file or directory on $hostName to write:"
  137.             tput rmul
  138.             read fileName
  139.  
  140.             # set up the path as rcp would for $login
  141.             case $fileName
  142.                 in
  143.                 ~* | /*)
  144.                     # leave as is.
  145.                     ;;
  146.                 *)
  147.                     fileName="~$login/$fileName"
  148.                     ;;
  149.             esac
  150.  
  151.             echo
  152.             echo "Attempting an rcp as $login."
  153.  
  154.             # Try as guest if no permission for user.
  155.             # Permission check for machine, not file.
  156.             errStr=`rsh "$hostName" -l "$login" echo 2>&1`
  157.             success=$?
  158.             echo "$errStr"
  159.             if [ $success -ne 0 ]; then
  160.                 if [ "$errStr" = "Permission denied." -o \
  161.                    "$errStr" = "Login incorrect." ]; then
  162.                 login=guest
  163.                 echo
  164.                 echo "Attempting an rcp as guest."
  165.                 success=0;
  166.                 fi
  167.             fi
  168.  
  169.             # RCP for real (if it makes sense).
  170.             if [ $success -eq 0 ]; then
  171.                 rcp -rv $SELECTED "$login@$hostName:$fileName"
  172.                 success=$?
  173.             fi
  174.             ;;
  175.         esac
  176.         echo
  177.         tput bold
  178.         if [ $success -ne 0 ]; then
  179.         echo NOT COMPLETED
  180.         else
  181.         echo SUCCESSFULLY COMPLETED
  182.         fi
  183.         tput rmul
  184.         exit 0
  185.     ;;
  186.     *)
  187.         echo Invalid argument: $1 1>&2
  188.         exit 1
  189.     ;;
  190. esac
  191. exit 0
  192.